package com.xyebank.ledger.util;

import com.xyebank.ledger.db.entitys.LedgerEntity;

import java.util.AbstractList;
import java.util.ArrayList;

public class SpecialArrayList<T extends LedgerEntity> extends AbstractList<T> {

    private ArrayList<T> list;

    private HashService hashService;

    public SpecialArrayList(){
        list = new ArrayList<>();
        hashService = new MD5HashServiceImp();
    }

    @Override
    public int size() {
        return list.size();
    }

    @Override
    public T get(int index) {
        return list.get(index);
    }

    @Override
    public boolean add(T e) {
        String hash = hashService.genHash(e);
        e.setHash(hash);
        return list.add(e);
    }

    @Override
    public T remove(int index){
        return list.remove(index);
    }

    @Override
    public boolean remove(Object o) {
        return list.remove(o);
    }
}
